//
//  CJPTabBarController.swift
//  CJPack
//
//  Created by 陈警卫 on 2023-04-20.
//

import UIKit

class CJPTabBarController: CJTabBarController {
    
    var tabBackColor: UIColor {
        return CJPColor.tabBack.color
    }
    var tabNormalColor: UIColor {
        return CJPColor.tabNormal.color
    }
    var tabSelectedColor: UIColor {
        return CJPColor.tabSelected.color
    }
    
    var homeNC: CJPRootController {
        return ncSetupTabBar(vc: PHomeController(), title: "Home", tabImage: "tab_discover")
    }
    var meNC: CJPRootController {
        return ncSetupTabBar(vc: PMeController(), title: "Me", tabImage: "tab_me")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupView()
    }
    
    override func cj_skinAction(_ kit: Any) {
        super.cj_skinAction(kit)
        setupSkin()
    }
    
    func setupSkin() {
        if let vcs = viewControllers {
            for nc in vcs {
                nc.tabBarItem.image = nc.tabBarItem.image?.cj_imageTint(color: tabNormalColor)
                nc.tabBarItem.selectedImage = nc.tabBarItem.selectedImage?.cj_imageTint(color: tabSelectedColor)
            }
        }
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.setNavigationBarHidden(true, animated: false)
    }
    
    func setupView() {
        self.view.backgroundColor = .clear
        viewControllers = [homeNC, meNC]
        selectedIndex = 0
    }
    
    func ncSetupTabBar(vc: UIViewController, title:String, tabImage:String) -> CJPRootController {
        let nc = CJPRootController(rootViewController: vc)
        nc.tabBarItem.image = UIImage(named: tabImage)?.cj_imageTint(color: tabNormalColor)
        nc.tabBarItem.selectedImage = UIImage(named: tabImage)?.cj_imageTint(color: tabSelectedColor)
        nc.title = title
        vc.title = title
        return nc
    }

}
